include ../rose.mk

#DBG         = -g
OPT         = -O3 
CFLAGS      = $(DBG) $(OPT)
CPP         = $(CXX)


EXTRA_LIBS  = 
LIBDIR      = .

SRCS        = \
	main.C \
	midend/MintCudaMidend.C \
	midend/CudaOutliner.C \
	midend/VariableHandling.C \
	midend/LoweringToCuda.C \
	midend/memoryManagement/CudaMemoryManagement.C \
	midend/memoryManagement/DataTransferSizes.C \
	midend/arrayProcessing/MintArrayInterface.C \
	midend/mintTools/MintTools.C \
	midend/mintTools/MintOptions.C \
	midend/mintPragmas/MintPragmas.C \
	optimizer/CudaOptimizer.C \
	optimizer/KernelMergeInterface.C \
	optimizer/OnChipMemoryOptimizer/OnChipMemoryOpt.C \
	optimizer/OptimizerInterface/CudaOptimizerInterface.C \
	optimizer/programAnalysis/StencilAnalysis.C \
	optimizer/programAnalysis/MintConstantFolding.C \
	optimizer/LoopUnroll/LoopUnrollOptimizer.C \
	optimizer/OnChipMemoryOptimizer/GhostCellHandler.C
	 

OBJ_DIR	     =obj
SUBDIR	    = $(OBJ_DIR)/optimizer $(OBJ_DIR)/midend $(OBJ_DIR)/midend/memoryManagement \
	$(OBJ_DIR)/midend/arrayProcessing $(OBJ_DIR)/midend/mintTools $(OBJ_DIR)/types \
	$(OBJ_DIR)/optimizer/OnChipMemoryOptimizer $(OBJ_DIR)/optimizer/OptimizerInterface \
	$(OBJ_DIR)/optimizer/programAnalysis $(OBJ_DIR)/midend/mintPragmas $(OBJ_DIR)/optimizer/LoopUnroll \


_OBJS	     =$(SRCS:%.C=%.o)
OBJS	     =$(patsubst %,$(OBJ_DIR)/%,$(_OBJS))

TARGET_BIN  = mintTranslator

all: createOBJDIR $(TARGET_BIN) install

createOBJDIR	:
	mkdir -p $(OBJ_DIR)
	mkdir -p $(SUBDIR)

$(OBJ_DIR)/%.o: %.C
	@echo 'Building file: $<'
	@echo 'Invoking: GCC C++ Compiler'
	$(CPP) $(CFLAGS) $(CXXFLAGS)  -c -o $@ $< -I$(INCLUDE)
	@echo 'Finished building: $<'
	@echo ' '

$(TARGET_BIN) : $(OBJS)
	@echo 'Invoking C++ Linker'
	$(LIB_TOOL) --mode=link $(CPP) $(CFLAGS) $(CXXFLAGS) -o $@ $^ $(ROSE_LIBS)  -L$(LIBDIR) $(EXTRA_LIBS) 
	@echo 'Finished building target: $@'
	@echo ' '

install: $(TARGET_BIN)
	@echo $(TARGET_BIN) is installed
	@echo ' '
clean: 
	rm -f core *.o $(OBJS) *~  $(TARGET_BIN) 

clean-tests: 
	rm -f core *.o  *~ *.c.pdf *.c.dot rose_*.c rose_*.cpp mint_*.cpp mint_*.cu mint_*.c 

depend:
	$(CPP) -E -MM -I$(INCLUDE) $(EXTRA_CFLGS) $(SRCS) > DEPENDS

include DEPENDS
